package com.example.backend.service;


import com.example.backend.entity.Shop;
import com.example.backend.mapper.ShopMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
public class ShopService {

    @Autowired
    private ShopMapper shopMapper;

    public int addShop(Shop shop) {
        shop.setState("0");
        return shopMapper.addShop(shop);
    }

    public int updateShop(Shop shop){
        int count = shopMapper.updateShop(shop);
        return count;
    }
    public int deleteShop(Integer id){
        int count = shopMapper.deleteShop(id);
        return count;
    }
    public Shop selectShopById(Integer id){
        Shop shop = shopMapper.selectShopById(id);
        return shop;
    }
    public ArrayList<Shop> selectAll(Shop shop){
        ArrayList<Shop> shops = shopMapper.selectAll(shop);
        return shops;
    }
    public Shop selectByShopname(String shopname){
        Shop shop = shopMapper.selectByShopname(shopname);
        return shop;
    }

    public PageInfo<Shop> shopGetPage(Integer pageNum, Integer pageSize, Shop shop) {
        PageHelper.startPage(pageNum, pageSize);
        List<Shop> list = shopMapper.selectAll(shop);
        return new PageInfo<>(list);
    }
    /**
     *更新商家评分
     */
    public int updateShopScore(Integer id){
        return shopMapper.updateShopScore(id);
    }
}
